<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>留言本系统V1.0</title>
	<style type="text/css">
	#liuyan{
		width: 60%;
		background-color: #ffffff;
		color: red;
		text-align: left;
		float: left;
		min-height: 500px;
		margin-right: 50px;
	}
	#liuyan_min{
		min-height: 600px;
	}
	#ly_content{
		color: #808080;
		padding: 10px;
		border-bottom: 1px dashed #808080; 
		padding-left: 20px;
	}
	#ly_party{
		color: green;
		font-weight: bold;
		margin-right: 20px;
		font-size: 11px;
		padding: 2px;
		border: 1px solid green;
	}
	#ly_title{
		color: black;
	}
	#ly_confirm{
		float: right;
		margin-right: 40px;
		color: red;
	}
	#ly_editor{
		margin-right: 20px;
	}
	#ly_total{
		float: right;
		margin-right: 40px;
	}
	#gonggaolianjie{
		background-color: #ffffff;
		float: left;
		width: 35%;
	}
	#gonggaolianjie h2{
		color: red;
	}
	#gonggaolian h2{
		float: left;
	}
	#gonggaolian a{
		float: right;
	    line-height: 70px;
	    margin-right: 50px;
	}
	#frame{
		border-top: 1px solid #4a5259;
		border-bottom: 1px solid #4a5259;
	}
	#ly_a{
		float: none;
		text-align: center;
		margin: 0 auto;
		margin-top: 20px;
		margin-bottom: 20px;
	}
	#ly_a a{
		 color: #000000;
		 text-align: center;;
	}
	a{
		text-decoration: none;
		color: black;
	}
	a:hover{
		text-decoration: underline;
	}
	ul{
		list-style: none;
	}
	</style>
</head>
<body>
<!--加载头部信息-->
<?php

include_once("header.php");
?>
<!--中间区域信息-->
<div id="liuyan">
<div id="liuyan_min">
<?php
include_once("database.php");
//判定一共有多少记录条数
$selecttotal="select subjectid from subject";
$result=mysql_query($selecttotal);
$totalrow=mysql_num_rows($result);//获取到需要分页的总记录数
//每页显示5条记录
//当前处于第几页
$currentpage=isset($_GET["pages"])?$_GET["pages"]:1;
//当前页面的limit的第一个参数
$startnum=($currentpage-1)*5;
//查询当前页面的记录
?>
<?php
//获取数据库表里的subject数据 然后显示出来
$selectsubject="select subjectid,type,title,questioner,dates,answers from subject order by dates desc limit $startnum,5";
$result=mysql_query($selectsubject);
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){

	$subjectid=$row["subjectid"];
	$type=$row["type"];
	$title=$row["title"];
	$questioner=$row["questioner"];
	$dates=$row["dates"];
	$answers=$row["answers"];
//字符串:单引号 双引号 定界符
	echo <<<subjectinfos
		<div id="ly_content">
			<p><span id="ly_party">{$type}</span><a href="xiangqing.php?action=show&subjectid={$subjectid}"><span id="ly_title">{$title}</span></a><a href="index.php?okdel={$title}" onclick="javascript:return confirm('是否确认删除{$title}')"><span id="ly_confirm">删除</span><a></p>
			<p><a href="xiangqing.php?action=show&subjectid={$subjectid}"><span id="ly_editor">{$questioner}</span><span id="ly_date">{$dates}</span><span id="ly_total">{$answers}</span></a></p>
		</div>
subjectinfos;

}
?>
</div>
<?php
if(isset($_GET["okdel"])){
	include_once("database.php");
	if(isset($_COOKIE["type"])&&$_COOKIE["type"]=="管理员") {
		//确定删除记录
	$title=$_GET["okdel"];
	$deletebooksql="delete from subject where title='{$title}'";
	@mysql_query($deletebooksql) or die("删除标题为:".$title." 的信息失败:".mysql_error()."<br/>");
	header("Refresh:2;url=index.php");
	}else{
		echo "<script>alert('你还不是管理员，没有删除权限');</script>";
	}
}

//判定一下当前一共有多少页
$totalpage=ceil($totalrow/5);//上取整
//如果总页数小于等于5 都显示出来
//首页
echo "<div id=\"ly_a\"><a href=\"index.php\">首页</a>&nbsp;&nbsp;";
if ($totalpage<=5) {
	for($i=1;$i<=$totalpage;$i++){
		echo "<a href=\"?pages={$i}\">第{$i}页</a>&nbsp;&nbsp;";
	}
}else{
	//总页数大于5
	//如果当前页面编号>=最后一页编号-4 直接显示最后5页
	if($currentpage>=$totalpage-4){
		for($i=$currentpage;$i<=$totalpage;$i++){
			echo "<a href=\"?pages={$i}\">第{$i}页</a>&nbsp;&nbsp;";
		}
	}else{//当前页面处于中间
		echo "<a href=\"?pages={$currentpage}\">第{$currentpage}页</a>&nbsp;&nbsp;";
		echo "<a href=\"?pages=".($currentpage+1)."\">第".($currentpage+1)."页</a>&nbsp;&nbsp;";
		
		echo "...";
		echo "<a href=\"?pages=".($totalpage-1)."\">第".($totalpage-1)."页</a>&nbsp;&nbsp;";
		echo "<a href=\"?pages={$totalpage}\">第{$totalpage}页</a>&nbsp;&nbsp;";

	}
}
//尾页
echo "<a href=\"?pages={$totalpage}\">尾页</a></div>";
?>

</div><!--//留言结束标签-->

<!--机房公告和友情链接-->
<div id="gonggaolianjie">
	<div id="gonggaolian">
		<h2>机房公告</h2>
		<?php 
		include_once("database.php");
		if(isset($_COOKIE["type"])&&$_COOKIE["type"]=="管理员") {
				echo '<a href="fabugonggao.php" >发布</a>';
			}
		?>
		

	</div>
	
	<iframe src="gonggao.php" name="iframe_main" id="frame" frameborder="0" width="100%" height="250">
		如果看到此处内容,则说明浏览器版本过低,升级浏览器即可!
	</iframe>
	<div id="gonggaolian">
	<h2>友情链接</h2>
	<?php 
		include_once("database.php");
		if(isset($_COOKIE["type"])&&$_COOKIE["type"]=="管理员") {
				echo '<a href="fabulink.php" >发布</a>';
			}
		?>
	</div>
	<iframe src="link.php" name="iframe_main" id="frame" frameborder="0" width="100%" height="250">
		如果看到此处内容,则说明浏览器版本过低,升级浏览器即可!
	</iframe>
</div>
<!--加载底部信息-->
<?php
include_once("footer.php");
?>
</body>
</html>